package com.apps.ftapp.service;

import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.Toast;

import com.allenliu.versionchecklib.core.AVersionService;
import com.apps.ftapp.bean.UpdModel;
import com.apps.ftapp.util.AppUtils;
import com.apps.ftapp.util.L;
import com.apps.ftapp.util.SharedPreferencesUtil;
import com.google.gson.Gson;

public class MyService1 extends AVersionService {

    private String downloadUrl = "";
    private String title = "";
    private String updateMsg = "";


    public MyService1() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onResponses(AVersionService service, String response) {
        //这里你解析response，判断是否更新以及是否强制更新，将参数传过去\

        Gson gson = new Gson();

        UpdModel model = gson.fromJson(response, UpdModel.class);


        boolean isForceUpdate = true;
        Bundle bundle = new Bundle();
        int clientVersion = AppUtils.getLocalVersion(getApplicationContext());
//        int serverVersion =model.get

        if ("1".equals(model.getIfsj())) {
            bundle.putBoolean("isForceUpdate", isForceUpdate);
            L.i("main", "===onResponsesonResponsesonResponsesonResponsesonResponsesonResponses=======" + clientVersion + "=====");
            service.showVersionDialog(model.getDurl(), "版本更新", model.getSjtext(), bundle);

//            SharedPreferencesUtil.saveData(getApplicationContext(),"isUpdate",true);


        }

//
//        if (serverVersion > clientVersion) {
//            //传入下载地址，以及版本更新消息
//            service.showVersionDialog(downloadUrl,title,updateMsg );
//            // or
//            service.showVersionDialog(downloadUrl,title,updateMsg,bundle);
//        }

//        showVersionDialog("http://down1.uc.cn/down2/zxl107821.uc/miaokun1/UCBrowser_V11.5.8.945_android_pf145_bi800_(Build170627172528).apk","test","test",bundle);
    }
}
